#登录业务

import allure

from page.page_index import PageIndex
from page.page_login import PageLogin
from page.page_user import PageUser

class ServiceLogin(object):
    def __init__(self,driver,base_url):
        #初始化页面对象
        self.pageIndex=PageIndex(driver,base_url)
        self.pageLogin=PageLogin(driver,base_url)
        self.pageUser=PageUser(driver,base_url)


    def service_login_001(self,d):
        allure.attach("1.XXX 2.XXX 3.XXXX", "第一步：打开首页")
        self.pageIndex.openUrl()

        allure.attach("", "第2步：点击首页页面上的登录按钮")
        self.pageIndex.click_login()

        allure.attach("", f"第3步：输入账号:{d['zanhao']}")
        self.pageLogin.input_zanhao(d["zanhao"])
        self.pageLogin.input_pwd(d["pwd"])
        self.pageLogin.click_login()

        siji=self.pageUser.getNichenText()
        imgName=self.pageUser.savePng2("登录",d["key"]) #"登录_K001_20251028171203.png"
        allure.attach(open(f'./screen/{imgName}', 'rb').read(), "第n步：登录成功后的截图",allure.attachment_type.PNG)
        yuqi=d["yuqi"]
        return siji==yuqi

    def service_login_002(self,d):
        self.pageIndex.openUrl()
        self.pageIndex.click_login()

        self.pageLogin.input_zanhao(d["zanhao"])
        self.pageLogin.input_pwd(d["pwd"])
        self.pageLogin.click_login()

        return self.pageLogin.isExistsErrorTips()

    def service_login_003(self,d):
        self.pageIndex.openUrl()
        self.pageIndex.click_login()

        self.pageLogin.input_zanhao(d["zanhao"])
        self.pageLogin.input_pwd(d["pwd"])
        self.pageLogin.click_login()

        return self.pageLogin.isHasZanhaoClass()

    def service_login_004(self,d):
        self.pageIndex.openUrl()
        self.pageIndex.click_login()

        self.pageLogin.input_zanhao(d["zanhao"])
        self.pageLogin.input_pwd(d["pwd"])
        self.pageLogin.click_login()

        return self.pageLogin.isHasPwdClass()